using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using System.Net.NetworkInformation;
using System.Security.Cryptography;

namespace RESTAURANT
{
    public class ComPuter
    {
        static public string GetKey()
        {
            string Key = GetMotherId().Trim();
            Key += GetCPUId().Trim();
            Key += GetHDDId().Trim();
            return Key;
        }
        static public  string TrimKey(string key)
        {
            int i;
            for (i = 0; i < key.Length; i++)
            {
                if (!(key[i] >= '0' && key[i] <= '9') && !(key[i] >= 'A' && key[i] <= 'Z') && !(key[i] >= 'a' && key[i] <= 'z'))
                {
                    key = key.Remove(i, 1);
                    i--;
                }
            }
            return key;
        }
      static  private string GetMotherId()
        {
            string id = string.Empty;

            ManagementObjectCollection mbsList = null;
            ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_BaseBoard");
            mbsList = mbs.Get();
            foreach (ManagementObject mo in mbsList)
            {
                try
                {
                    if (id == string.Empty)
                        id = mo["SerialNumber"].ToString();
                }
                catch (Exception)
                {
                    id = string.Empty;
                }
            }

            if (id == string.Empty)

                id = "11FFAAA0DBC";



            return id;
        }
      static  private string GetCPUId()
        {
            String id = String.Empty;
            ManagementObjectCollection mbsList = null;
            ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_processor");
            mbsList = mbs.Get();
            foreach (ManagementObject mo in mbsList)
            {
                try
                {
                    if (id == string.Empty)
                        id = mo["ProcessorID"].ToString();
                }
                catch (Exception)
                {
                    id = string.Empty;
                }
            }
            if (id == string.Empty)

                id = "FFFEEA1A2HEO0982";

            return id;
        }
       static private string GetHDDId()
        {
            string id = string.Empty;
            ManagementObjectCollection mbsList = null;
            ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_PhysicalMedia");
            mbsList = mbs.Get();
            foreach (ManagementObject mo in mbsList)
            {
                try
                {
                    if (id == string.Empty)
                        id = mo["SerialNumber"].ToString();
                }
                catch (Exception)
                {
                    id = string.Empty;
                }
            }
            if (id == string.Empty)

                id = "KL0112HT19HEO11ECH";

            return id;
        }

        static private string GetMac()
        {
            string t = "";
            int j = 0;
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();

            PhysicalAddress address = nics[j].GetPhysicalAddress();

            byte[] bytes = address.GetAddressBytes();

            for (int i = 0; i < bytes.Length; i++)
            {
                t += bytes[i].ToString("X2");
            }
            return t;
        }


    }
}
